package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.dto.*;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.AcctService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zhouxu
 * @create 2020-12-18 17:44
 */
@RestController
@RequestMapping("/acct")
public class AcctController {

    @Autowired
    private AcctService acctService;

    @ApiOperation(value = "账本余额查询", response = AjaxData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "acctType", value = "账本类别 F Y G", paramType = "query", dataType = "string", required = true),
    })
    @RequestMapping(value = "queryAcctBalance", method = RequestMethod.GET)
    public AjaxData queryAcctBalance(String acctType) {
        return acctService.queryAcctBalance(UserContext.getUserId(), acctType);
    }

    @ApiOperation(value = "账本日志查询", response = AjaxData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "页大小", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "acctType", value = "账本类别 F Y G", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "feeInDe", value = "增减 1-增,2-减少", paramType = "query", dataType = "string", required = false),
    })
    @RequestMapping(value = "listAcctLog", method = RequestMethod.GET)
    public AjaxPage<AcctRecordVo> listAcctLog(Integer page, Integer limit,
                                              String acctType, String feeInDe) {
        return acctService.listAcctLog(page, limit, UserContext.getUserId(), acctType, feeInDe);
    }


    @ApiOperation(value = "福币购买", response = AjaxData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "购买福币入参", dataType = "BuyFCoinDto")
    })
    @PostMapping(value = "buyFCoin")
    public AjaxData buyFCoin(@RequestBody BuyFCoinDto dto) {
        return acctService.buyFCoin(UserContext.getUserId(),
                dto.getType(), dto.getNum(), dto.getPayWay(), dto.getRfId(), dto.getExpend());
    }

    @ApiOperation(value = "福币购买页面查询", response = RnbBuyFCoinVo.class)
    @RequestMapping(value = "buyFCoinView", method = RequestMethod.GET)
    @ResponseBody
    public AjaxPage<RnbBuyFCoinVo> buyFCoinView() {
        return acctService.buyFCoinView(UserContext.getUserId());
    }


    @ApiOperation(value = "果子购买", response = AjaxData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dto", value = "购买果子入参", dataType = "BuyFCoinDto")
    })
    @PostMapping(value = "buyGzCoin")
    public AjaxData buyGzCoin(@RequestBody BuyGzCoinDto dto) {
        return acctService.buyGzCoin(UserContext.getUserId(),
                dto.getType(), dto.getNum(), dto.getPayWay(), dto.getRgId(), dto.getExpend());
    }

    @ApiOperation(value = "果子购买页面查询", response = RnbBuyGzCoinVo.class)
    @RequestMapping(value = "buyGzCoinView", method = RequestMethod.GET)
    @ResponseBody
    public AjaxPage<RnbBuyGzCoinVo> buyGzCoinView() {
        return acctService.buyGzCoinView(UserContext.getUserId());
    }


    @ApiOperation(value = "钱包信息", response = AcctGlobalVo.class)
    @RequestMapping(value = "/AcctInfo", method = RequestMethod.GET)
    @ResponseBody
    public AjaxData<AcctGlobalVo> AcctInfo() {
        return acctService.acctInfo(UserContext.getUserId());
    }

    @ApiOperation("转账")
    @ApiImplicitParam(name = "dto", value = "转账参数", dataType = "TransferDto")
    @PostMapping("transfer")
    public AjaxData transfer(@RequestBody TransferDto dto) {
        return acctService.transfer(
                "G", dto.getMoney(), UserContext.getUserId(), dto.getToUserId(),
                dto.getTradePwd()
        );
    }

    @ApiOperation("查询银行编码列表")
    @GetMapping("listBankCode")
    public AjaxPage<BankCodeVo> listBankCode() {
        return acctService.listBankCode();
    }

    @ApiOperation("查询银行编码列表")
    @GetMapping("listBankCodeCh")
    public AjaxPage<BankCodeVo> listBankCodeCh() {
        return acctService.listBankCodeCh();
    }

    @ApiOperation("查询银行卡列表")
    @GetMapping("listBank")
    public AjaxPage<UserBankVo> listBank() {
        return acctService.listBank(UserContext.getUserId());
    }

    @ApiOperation("保存支付宝信息")
    @ApiImplicitParam(name = "model", value = "保存支付宝参数", dataType = "AddUserAliDto")
    @PostMapping("saveAliPay")
    public AjaxData saveAliPay(@RequestBody AddUserAliDto model) {
        return acctService.saveAliPay(UserContext.getUserId(), model.getRealName(),
                model.getAliNo(), model.getReceQrCode());
    }

    @ApiOperation("保存银行卡信息")
    @ApiImplicitParam(name = "model", value = "保存银行卡信息参数", dataType = "UserBankDto")
    @PostMapping("saveBankPay")
    public AjaxData saveBankPay(@RequestBody UserBankDto model) {
        return acctService.saveBankPay(model.getBankId(), UserContext.getUserId(),
                model.getRealName(), model.getCarNo(), model.getBankName(),
                model.getOpenBank(), model.getDefaultFlag(), model.getProvince(), model.getCity(), model.getBankCode());
    }

    @ApiOperation("删除银行卡信息")
    @ApiImplicitParam(name = "model", value = "保存银行卡信息参数", dataType = "DeleteBankDto")
    @PostMapping("deleteBankPay")
    public AjaxData deleteBankPay(@RequestBody DeleteBankDto model) {
        return acctService.deleteBankPay(model.getBankId(), UserContext.getUserId());
    }

    @ApiOperation("保存微信支付信息")
    @ApiImplicitParam(name = "model", value = "保存微信信息参数", dataType = "AddUserWechatDto")
    @PostMapping("saveWechatPay")
    public AjaxData saveWechatPay(@RequestBody AddUserWechatDto model) {
        return acctService.saveWechatPay(UserContext.getUserId(), model.getRealName(),
                model.getWechatNo(), model.getReceQrCode());
    }

    @ApiOperation("银行卡设置默认")
    @ApiImplicitParam(name = "dto", value = "设置默认", dataType = "UpdateBankDto")
    @PostMapping("updateDefaultFlag")
    public AjaxData updateDefaultFlag(@RequestBody UpdateBankDto dto) {
        return acctService.updateDefaultFlag(dto.getBankId());
    }

    @ApiOperation("查询红包统计信息")
    @GetMapping("redPackStatistics")
    public AjaxData<RedPackStatisticsVo> redPackStatistics() {
        return acctService.redPackStatistics(UserContext.getUserId());
    }

    @ApiOperation(value = "获取红包记录")
    @RequestMapping(value = "/listRedPackLog", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<RedPackLogVo> listRedPackLog(int pageNumber, int pageSize) {
        return acctService.listRedPackLog(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation("私人红包-发")
    @ApiImplicitParam(name = "dto", value = "私人红包-发", dataType = "RedPackPersonSendDto")
    @PostMapping("redPackPersonSend")
    public AjaxData redPackPersonSend(@RequestBody RedPackPersonSendDto dto) {
        return acctService.redPackPersonSend(UserContext.getUserId(), dto.getOtherId(), dto.getMoney(), dto.getTitle(), dto.getTradePwd());
    }

    @ApiOperation("私人红包-收")
    @ApiImplicitParam(name = "dto", value = "私人红包-收", dataType = "RedPackPersonRecvDto")
    @PostMapping("redPackPersonRecv")
    public AjaxData redPackPersonRecv(@RequestBody RedPackPersonRecvDto dto) {
        return acctService.redPackPersonRecv(UserContext.getUserId(), dto.getRedPackId());
    }

    @ApiOperation("直播间发红包")
    @ApiImplicitParam(name = "dto", value = "直播间发红包", dataType = "RedPackLiveSendDto")
    @PostMapping("redPackLiveSend")
    public AjaxData redPackLiveSend(@RequestBody RedPackLiveSendDto dto) {
        return acctService.redPackLiveSend(UserContext.getUserId(), dto.getLiveId(), dto.getNum(),
                dto.getMoney(), dto.getTitle(), dto.getTradePwd(), dto.getEffTime());
    }

    @ApiOperation("直播间抢红包")
    @ApiImplicitParam(name = "dto", value = "直播间抢红包", dataType = "RedPackLiveTakeDto")
    @PostMapping("redPackLiveTake")
    public AjaxData redPackLiveTake(@RequestBody RedPackLiveTakeDto dto) {
        return acctService.redPackLiveTake(UserContext.getUserId(), dto.getRedPackId());
    }

    @ApiOperation("音值提现")
    @ApiImplicitParam(name = "dto", value = "音值提现", dataType = "CashOutYCoinDto")
    @PostMapping("cashOutYCoin")
    public AjaxData cashOutYCoin(@RequestBody CashOutYCoinDto dto) {
        return acctService.cashOutYCoin(UserContext.getUserId(), dto.getNum(),
                dto.getTradePwd(), dto.getPayMethod(), dto.getBankId());
    }

    @ApiOperation("果子提现")
    @ApiImplicitParam(name = "dto", value = "果子提现", dataType = "CashOutGzCoinDto")
    @PostMapping("cashOutGzCoin")
    public AjaxData cashOutGzCoin(@RequestBody CashOutGzCoinDto dto) {
        return acctService.cashOutGzCoin(UserContext.getUserId(), dto.getNum(),
                dto.getTradePwd(), dto.getPayMethod(), dto.getBankId());
    }

    @ApiOperation("查询银行卡省市")
    @GetMapping("listBankDistrict")
    public AjaxPage<BankDistrictTreeVo> listBankDistrict() {
        return acctService.listBankDistrict(UserContext.getUserId());
    }

    @ApiOperation("查询支付信息")
    @GetMapping("paymentInformation")
    public AjaxData paymentInformation() {
        return acctService.paymentInformation(UserContext.getUserId());
    }

    @ApiOperation("查询果子提现信息")
    @GetMapping("getGzCashInfo")
    public AjaxData<GzCashInfoVo> getGzCashInfo() {
        return acctService.getGzCashInfo(UserContext.getUserId());
    }

    @ApiOperation("查询微信支付信息")
    @GetMapping("queryWechatPay")
    public AjaxData queryWechatPay() {
        return acctService.queryWechatPay(UserContext.getUserId());
    }

    @ApiOperation("查询支付宝信息")
    @GetMapping("queryAliPay")
    public AjaxData queryAliPay() {
        return acctService.queryAliPay(UserContext.getUserId());
    }


    @ApiOperation(value = "查询直播间红包")
    @RequestMapping(value = "/queryLiveRedpack", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播间标识", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxData<LiveRedPackVo> queryLiveRedpack(Long liveId) {
        return acctService.queryLiveRedpack(UserContext.getUserId(), liveId);
    }

    @ApiOperation(value = "观众抢红包记录")
    @RequestMapping(value = "/listTakeRedPackLog", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "redPackId", value = "红包标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "page", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "limit", value = "页大小", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "changeType", value = "红包类型 1 私人红包， 2直播红包", paramType = "query", dataType = "string", required = false),
    })
    @ResponseBody
    public AjaxPage<RedPackLogVo> listTakeRedPackLog(Long redPackId, String changeType, Long page, Long limit) {
        return acctService.listTakeRedPackLog(UserContext.getUserId(), redPackId, changeType, page, limit);
    }


    @ApiOperation(value = "查询私人发的红包")
    @RequestMapping(value = "/listPersonSendPack", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fromUserId", value = "发红包的人", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "page", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "limit", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<RedPackLogVo> listPersonSendPack(Long fromUserId, Long page, Long limit) {
        return acctService.listPersonSendPack(UserContext.getUserId(), fromUserId, page, limit);
    }

    @ApiOperation(value = "红包详情")
    @RequestMapping(value = "/redPackDetails", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "redId", value = "红包标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "tradeType", value = "交易类型", paramType = "query", dataType = "String", required = true)
    })
    @ResponseBody
    public AjaxData<RedPackDetailsVo> redPackDetails(Long redId, String tradeType) {
        return acctService.redPackDetails(redId, tradeType);
    }

    @ApiOperation("检查授权许可")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query", dataType = "string", required = true)
    })
    @GetMapping("checkLicence")
    public AjaxData checkLicence(String code) {
        return acctService.checkLicence(code);
    }

    @ApiOperation(value = "查询果子账户信息")
    @RequestMapping(value = "getGzAcctInfo", method = RequestMethod.GET)
    public AjaxData<AcctGzGlobalVo> getGzAcctInfo() {
        return acctService.getGzAcctInfo(UserContext.getUserId());
    }

    @ApiOperation(value = "查询团队果子价格")
    @RequestMapping(value = "listTeamGzPrice", method = RequestMethod.GET)
    public AjaxPage<TeamGzPriceVo> listTeamGzPrice() {
        return acctService.listTeamGzPrice(UserContext.getUserId());
    }

}
